﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Quan_Ly_Phong_Kham_co_len_em.AddID
{
    public static class Ham_Tu_Tang
    {
        public static DataTable Select_Max(string dtb, string ma)
        {
            SqlConnection ketnoi = new SqlConnection("Data Source=NGUYENTY-PC\\SQLEXPRESS;Initial Catalog=QL_PHONGKHAM;Integrated Security=True");
            ketnoi.Open();

            SqlCommand cmd = new SqlCommand(@"Select MAX(" + ma + ") as id From " + dtb + " ", ketnoi);
            DataTable tmp = new DataTable();
            tmp.Load(cmd.ExecuteReader());
            return tmp;
        }
        public static string AddID(string chuoi, int m, int n) 
        {
            try
            {
                string s = chuoi.Trim();
                int len = s.Length;

                string chuoi_sau = s.Substring(n);
                string chuoi_dau = s.Substring(0, m);

                int so = Convert.ToInt32(chuoi_sau);
                so = so + 1;

                if (so <= 9)
                    chuoi_dau += '0';

                chuoi_dau += so;

                return chuoi_dau;
            }
            catch { return null; }
        }

    }
}
